package cn.com.generaldata.os.service.indicator_evaluation.composition_analysis;

import org.apache.commons.lang3.Validate;

import cn.com.generaldata.jsme_indicator_system.entity.IndicatorEvaluation;
import cn.com.generaldata.jsme_indicator_system.util.Constants;
import cn.com.generaldata.os.service.indicator_constant.ProvinceIndicatorConstant;
import cn.com.generaldata.os.service.indicator_evaluation.IndicatorEvaluationCalculateService;
import cn.com.generaldata.os.vo.IndicatorAccountVO;

/**
 * 海洋第一产业总值占比重评估指标计算类.
 */
public class FirstIndustrytoGOPCalculateService extends IndicatorEvaluationCalculateService {

	private String GOPIndicatorName = ProvinceIndicatorConstant.GOP_INDICATOR_NAME;
	private String FirstIndicatorName = ProvinceIndicatorConstant.FIRST_INDICATOR_NAME;

	@Override
	protected Double calculate(IndicatorEvaluation indicator, IndicatorAccountVO indicatorAccountVO) {
		Double result = null;
		if (indicator.getSection() == Constants.INDICATOR_LEVEL_PROVINCE) {
			result = calculateResult(indicatorAccountVO);
		} else if (indicator.getSection() == Constants.INDICATOR_LEVEL_CITY) {
			result = calculateCityResult(indicator, indicatorAccountVO);
		} else {
			// 县指标没确定先保留
		}
		return result;
	}

	/**
	 * 计算市级指标
	 * 
	 * @param indicatorAccountVO
	 * @return
	 */
	private Double calculateCityResult(IndicatorEvaluation indicator, IndicatorAccountVO indicatorAccountVO) {
		// if (indicatorAccountVO.getAreaId().equals("320900000000000")) {
		// // return calculateOtherCity(indicatorAccountVO);
		// IndicatorAccountVO vo = BeanMapper.map(indicatorAccountVO, IndicatorAccountVO.class);
		// vo.setAreaId(ProvinceIndicatorConstant.OTHER_CITY_AREA_ID);
		// calculateOtherCity(indicator, vo);
		// }
		return calculateResult(indicatorAccountVO);

	}

	private Double calculateResult(IndicatorAccountVO indicatorAccountVO) {
		Double GOP = getInputOrAccountingIndicatorValue(indicatorAccountVO, indicatorAccountVO.getYear(),
				GOPIndicatorName);
		Validate.isTrue(GOP != null);

		Double firstIndustryAddvalue = getInputOrAccountingIndicatorValue(indicatorAccountVO,
				indicatorAccountVO.getYear(),
				FirstIndicatorName);
		Validate.isTrue(firstIndustryAddvalue != null);

		return (firstIndustryAddvalue / GOP) * 100;
	}

}
